<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据字典管理</span>
      </div>

      <el-table
        :data="resList"
        style="width:100%"
        row-key="id"
        lazy
        :load="getChildrens"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column label="名称" align="left">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="编码">
          <template slot-scope="{ row }">
            {{ row.dictCode }}
          </template>
        </el-table-column>
        <el-table-column label="值" align="left">
          <template slot-scope="scope">
            <span>{{ scope.row.value }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getDictList } from "@/api/dict";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      resList: []
    };
  },
  created() {
    this.getDictList(1);
  },
  methods: {
    getDictList(id) {
      getDictList(id).then(response => {
        this.resList = response.data;
      });
    },
    getChildrens(tree, treeNode, resolve) {
      getDictList(tree.id).then(response => {
        resolve(response.data);
      });
    }
  }
};
</script>
